﻿<!DOCTYPE html>
<!--职务编辑-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/common.js"></script>


    <style>
        .el-input-number__increase {
            right: -4px;
        }

        .el-input-number.is-controls-right .el-input-number__decrease {
            right: -4px;
        }

    </style>
</head>

<body>
    <div id="app" v-cloak class="popupW100">
        <el-form :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px" size="mini" label-position="right">
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item prop="name">
                            <el-input type="text" v-model="Form.name" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{SysDuty.Name+mark.m}}
                                </template>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.name">
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
                <!--工厂-->
                <input-factorys-all :disabled ="allowModify" :span="11" :offset="2"  @change="factoryChange"  v-model="Form.createFactory"></input-factorys-all>
            </el-row>
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item prop="sysDepartmentID">
                            <el-input size="mini">
                                <template slot="prepend">
                                    {{"部门："}}
                                </template>
                                <treeselect v-model="Form.sysDepartmentID"
                                            :options="department"
                                            :flat="true"
                                            :show-count="true"
                                            slot="suffix"
                                            style="line-height: 28px;"
                                            placeholder="请选择" />
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.sysDepartmentID">
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11" :offset="2">

                </el-col>
            </el-row>
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item prop="isLeader">
                            <el-input size="mini">
                                <template slot="prepend">
                                    <div> {{SysDuty.IsLeader+mark.m}}</div>
                                </template>
                                <el-select @visible-change="visibleChange" v-model="Form.isLeader" slot="suffix" :placeholder="SysDuty.IsLeader">
                                    <el-option label="请选择" value=""></el-option>
                                    <el-option label="是" value="1"></el-option>
                                    <el-option label="否" value="0"></el-option>
                                </el-select>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.isLeader">
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>

                <el-col :span="11" offset="2">
                    <div class="elst-select-mini">
                        <div class="el-input el-input--mini el-input-group el-input-group--prepend">
                            <div class="el-input-group__prepend">
                                {{SysDuty.Position+mark.m}}
                            </div>
                            <div>
                                <el-input-number class="el-input__inner" v-model="Form.position" :min="1" label="描述文字" size="mini">
                                </el-input-number>
                            </div>

                        </div>
                    </div>

                </el-col>

            </el-row>



            <el-row type="flex" justify="end">
                <el-form-item>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSubmit}}</el-button>
                    <!-- <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSubmit}}</el-button> -->
                    <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>

    </div>
    <script type="text/javascript">
        Vue.component('treeselect', VueTreeselect.Treeselect)
        app = new Vue({
            el: '#app',
            data: {
                //父业传参
                id: '',
                allowModify: false,
                //业务表单内容
                Form: {
                    name: '',
                    createFactory: null,
                    sysDepartmentID: null,
                    isLeader: null,
                    position:1
                },
                factory: [],
                department:[],
                //表单验证
                rules: {
                    name: [verification.NotNull],
                    sysDepartmentID: [verification.NotNullSelect],
                    isLeader: [verification.NotNullSelect]
                }
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                 factoryChange: function () {
                    this.getDepartmentData();
                   
                },
                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            onSubmitForm(this, '/api/SysDuty/Save', mythis.Form);
                        } else {
                            //验证失败
                            return false;
                        }
                    });
                },
                getData: function () {
                    getData(this, '/api/SysDuty/get?id=' + this.id);
                },
                getDepartmentData: function () {
                    var mythis = this;
                    myAjax("post", this, '/api/SysDepartment/GetList', { model: { Name: '', Code: '', CreateFactory: mythis.Form.createFactory }, offset: 0, limit: 999 }, function (response) {
                        mythis.department = menuHelperX(response.data.pageData, guidEmpty)
                    }, false);
                },
            },
            mounted: function () {
                //this.factory = getDicData(['9002'])
                this.id = getUrlParam("id");
                this.getData();
                console.log('Form', this.Form);
                if (this.id != null) {
                    this.allowModify = true;
                }

            }
        });


        //下拉树数据格式化
        function menuHelperX(list, pid) {
            var result = [];
            if (list.length <= 0)
                return list;
            list.forEach(function (v, i) {
                var temp = {};
                for (var key in v) {
                    temp[key] = v[key];
                }
                temp.label = v.name;
                temp.parentId = temp.parentId ? temp.parentId : guidEmpty;
                var obj;
                if (temp.parentId == pid) {
                    obj = temp;
                    var nextObj = menuHelperX(list, temp.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;
        }
    </script>
</body>

</html>